package com.tanhua.management.controller;

import com.tanhua.management.service.LoggerService;
import com.tanhua.management.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("manage/logs")
public class LogController {

    @Autowired
    private LoggerService logService;

    @GetMapping//query参数
    public ResponseEntity<PageResult> Log(@RequestParam(name = "pagesize") Integer pageSize,
                                          @RequestParam(name = "page") Integer page,
                                          @RequestParam(name = "sortProp") String sortProp,
                                          @RequestParam(name = "sortOrder", defaultValue = "ascending") String sortOrder,

                                          @RequestParam(name = "uid") Long uid){


        try {

            PageResult pageResult = logService.logList(uid, pageSize,page, sortProp,sortOrder);
            if (null != pageResult) {
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

    }
}
